#include<iostream>
using namespace std;
typedef struct node{
	char data;
	struct node *lchild;
	struct node *rchild;
}BTNode;
BTNode *CreateBT1(char *pre,char *in,int n);
int GetHeight( BTNode *BT );
int main()
{
	int N;
	cin>>N;
	char pre[100],in[100];
	cin>>pre;
	cin>>in;
	BTNode *root=CreateBT1(pre,in,N);
	int high = GetHeight(root);
	cout<<high;
	return 0;
	
}
BTNode *CreateBT1(char *pre,char *in,int n)
{
	BTNode *b;
	char *p;
	int k;
	if(n<=0) return NULL;
	b=new BTNode;
	b->data= *pre;
	for(p=in;p<in+n;p++)
	 if(*p == *pre)
	  break;
	k=p-in;
	b->lchild=CreateBT1(pre+1,in,k);
	b->rchild=CreateBT1(pre+1+k,p+1,n-k-1);
	return b;
}
int GetHeight( BTNode *BT )
{
	if(BT==NULL) return 0;
	int L,R;
	L=GetHeight(BT->lchild);
	R=GetHeight(BT->rchild);
	return(L>R)?(L+1):(R+1);
} 
